<?php
class serialQuery extends EngineSupervisor
{
        private $db;

        public function __construct()
        {
                $this-> db = new dataBase();
        }

        public function getSerialShows()
        {
            
        }

        public function getSerialSeasons($serialTitle)
        {
//            $sQuery = "SELECT "
        }

        public function getOldserials()
        {
            $sQuery = "SELECT * from odcinek";
            $aResult = $this -> db -> PdoQuery($sQuery, array());

            return $aResult;
        }

        public function setNewShows($id, $idserialu, $megalink, $season, $episode, $title, $content) 
        {
            $sQuery = "INSERT INTO shows(id, serial_id, name, link, creation_date, description, season, episode) VALUES (?,?,?,?,now(),?,?,?)";
            $aResult = $this -> db -> ModifyQuery($sQuery, array($id, $idserialu, $title, $megalink, $content, $season, $episode));

            return $aResult;
        }

        public function getSeasonSerialsNew($serialId, $season)
        {
            $sQuery = "SELECT * FROM shows WHERE serial_id=? AND season=? ORDER BY episode";
            $aResult = $this -> db -> PdoQuery($sQuery, array($serialId, $season));

            return $aResult;
        }

        public function getSerialCategories($serialId)
        {
            $sQuery = "SELECT c.* FROM categories c, categories_serials cs WHERE cs.category_id=c.id AND cs.serial_id=? ORDER BY c.name";
            $aResult = $this -> db -> PdoQuery($sQuery, array($serialId));

            return $aResult;
        }

        public function getShowDatails($serialId, $sesionNumber, $episodeNumber)
        {
            $sQuery = "SELECT * FROM shows WHERE serial_id=? AND season=? AND episode=? ";
            $aResult = $this -> db -> PdoQuery($sQuery, array($serialId, $sesionNumber, $episodeNumber));

            return $aResult;
        }

        public function getSerialComments($serialId)
        {
            $sQuery = "SELECT c.*,u.* FROM users u, comments c WHERE u.id = c.user_id AND c.serial_id=? ORDER BY added_date DESC";
            $aResult = $this -> db -> PdoQuery($sQuery, array($serialId));

            return $aResult;
        }
        
        public function getLastEpisode($epId)
        {
            $sQuery = "SELECT * FROM last_watch WHERE episode_id=?";
            $aResult = $this -> db -> PdoQuery($sQuery, array($epId));

            return $aResult;
        }

        public function deleteEpisode($id)
        {
            $sQuery = "DELETE FROM last_watch WHERE id = ? ";
            $aResult = $this -> db -> ModifyQuery($sQuery, array($id));

            return $aResult;
        }

        public function getCountofFavourites($serialId)
        {
            $sQuery = "SELECT fs.*, (SELECT avatar FROM users u WHERE u.id=fs.user_id) as avatar FROM favourites_serials fs WHERE fs.serial_id=?";
            $aResult = $this -> db -> PdoQuery($sQuery, array($serialId));

            return $aResult;
        }
}

?>
